<%
Class Catelog
'Catelog

Private IcatName	'	
private IcatMdb		'=	"L_cat"				'数据库
private sqlstr
'-------------------------------------------
Property Get PIcatMdb
	PIcatMdb=IcatMdb
End Property
Property Let PIcatMdb(catMdb)
	IcatMdb=catMdb
End Property
'


'-------------------
public Function AddNew(arrstr)				'传入一维数组
	if not isarray(arrstr) then 
		AddNew = false
		exit Function
	End If
	Dim newCatPath
	newCatPath = Replace(ClearHtml(HTMLEncode( arrstr(4))),"'","")
	If(Len(newCatPath)>0) Then 
		If(In_Array(newCatPath,ProtectDiretorys)) Then 
			If(AutoFormatCatalogueFile) Then 
				Response.write("输入不安全文件夹，已经被格式")
				newCatPath = Generator(8)
			Else
				Response.write("警告:您输入不安全文件夹")
			End If 
		End If 
	End If 
	sqlstr= "select cat_name from "&IcatMdb&" order by cat_id desc"
	'	response.write (sqlstr)
	if Exist(GetRows(sqlstr),arrstr(0)) then 
		AddNew = false 
	else
		sqlstr ="insert into  "&IcatMdb&"(cat_name,cat_level,cat_parent,cat_other,cat_path) values('"&arrstr(0)&"',"&arrstr(1)&","&arrstr(2)&",'"&arrstr(3)&"','"& newCatPath &"')"
		on error resume next
		conn.execute(sqlstr)
		If Err Then
			response.write (err.Description)
			err.Clear
			AddNew = false 
		else
			AddNew = true
		End if
	End if
End Function
public Function Delete(cat_id)
		sqlstr="delete from  "&IcatMdb&"  where [cat_id]="&cat_id&""
		on error resume next
		conn.execute(sqlstr)
		If Err Then
			response.write (err.Description)
			err.Clear
			Delete = false 
		else
			Delete = true
		End if

End Function 
'---------------------
public Function GetCatAll()
	sqlstr = "select [cat_id],[cat_name],[cat_level],[cat_parent],[cat_other],[cat_path] from "&IcatMdb&" order by [cat_level] asc"
	GetCatAll = GetRows(sqlstr)
End Function 
public Function GetById(ids)
	sqlstr="select [cat_id],[cat_name],[cat_level],[cat_parent],[cat_other],[cat_path] from "&IcatMdb&" where [cat_id]="&ids&" order by cat_id desc"
	GetById =  GetRows(sqlstr) 
End Function 
public Function Edit(arrs)
	Dim newCatPath
	newCatPath = Replace(ClearHtml(HTMLEncode( arrs(5))),"'","")
	If(Len(newCatPath)>0) Then 
		If(In_Array(newCatPath,ProtectDiretorys)) Then 
			If(AutoFormatCatalogueFile) Then 
				Response.write("输入不安全文件夹，已经被格式")
				newCatPath = Generator(8)
			Else
				Response.write("警告:您输入不安全文件夹,但未被格式化,相关参数{AutoFormatCatalogueFile}")
			End If 
		End If 
	End If 
	sqlstr= "update "&IcatMdb&"  set [cat_name] = '"&arrs(1)&"',[cat_other] = '"&arrs(4)&"',[cat_level] = "&arrs(2)&",[cat_parent] = "&arrs(3)&",[cat_path]='"& newCatPath &"' where [cat_id]="&arrs(0)&"  "
		on error resume next
		conn.execute(sqlstr)
		If Err Then
			response.write (err.Description)
			err.Clear
			Edit = false 
		else
			Edit = true
		End if
End Function 

'---------------------
private Function Exist(arrs,str)
	Dim ai,booltf
	booltf = false 
	if isarray(arrs) then 
		for ai=0 to ubound(arrs,2)				'2维数组
			if str = arrs(0,ai) then 
				booltf = true 
			End if
		next 
	else
			if str = arrs then 
				booltf = true 
			End if
	End if
	Exist =	booltf
End Function 
'-------------------------------------------
End class
%>